<?php
namespace app\activity\model;
use think\Model;
class Customer extends Model{
    protected $table = 'bk_customer';
    protected $autoWriteTimestamp = 'datetime';
    const BELONG_STATUS = [
        0=>'待验证',
        1=>'进行中',
        2=>'已完成',
    ];
    const REACH_STATUS = [
        0=>'暂未达标',
        1=>'资产达标',
    ];
    public function inner()
    {
        return $this->hasOne('Customer','parentid','id');
    }

    public function getInfo($where){
        return self::where($where)->find();
    }

    public function getList($where=[],$order=['id'=>'desc']){
        return self::where($where)->order($order)->select();
    }

    public function addCustomer($data){
        return self::create($data);
    }

    public function updateCustomer($data){
        return self::where('id', $data['id'])->update($data);
    }

    public function getCount($where=[]){
        return self::where($where)->count();
    }

    public function getValue($where=[],$column='id'){
        return self::where($where)->value($column);
    }

    public function getPageList($page=0,$limit=2,$where=[],$order=['id'=>'desc']){
        return self::where($where)->order($order)->limit($page,$limit)->select();
    }

    public function Customer(){
        return $this->belongsTo('Customer','parentid','id');
    }

    public function Manager(){
        return $this->belongsTo('Manager','manager_id');
    }
}